<template>
	<view class="assemblyOrder-container">
		<view class="dome pt20 pb50 pl20 pr20 ">
			
			<view class="aCenter">
				<view class="workOrder">
					工单
				</view>
				
				<view class="workOrder_number">
					{{ info.saleOrderCode || '' }}
				</view>
			</view>
			
			<view class="jBetween aCenter" style="margin-top: 14rpx;">
				<view class="aCenter">
					<view class="jCenter" style="width: 70rpx;">
						<image style="width: 48rpx; height: 48rpx;" src="/static/images/time_icon.png" mode=""></image>
					</view>
				
					<view class="workOrder_number">
						{{ info.createTime || '' }}-{{ info.deliveryDate || '' }}
					</view>
				</view>
				
				<view @click="expand=!expand" class="" style="font-size: 24rpx;">
					展开/关闭
				</view>
			</view>
			
			
			<view class="aCenter jCenter" v-if="expand">
				<image :src="info.fileUrl" mode="widthFix"></image>
			</view>
			
			
			
			
			<view class="flex mb10" style="margin-top: 16rpx;">
				<view class="w200" style="color: #B4B4B4;">
					LOGO名称:
				</view>
				<view class="w480" style="word-break: break-word;color: #A3BD92;">
					{{ info.customerName || '' }}({{info.personCount || ''}})
				</view>
			</view>
			
			<view class="flex mb10">
				<view class="w200" style="color: #B4B4B4;">
					订单数量:
				</view>
				<view class="w480" style="word-break: break-word;color: #A3BD92;">
					{{ info.applyNumber }}
				</view>
			</view>
			
			
			<view class="dividingLine" style="margin-top: 20rpx;"></view>
			
			<view class="flex mb10">
				<view class="w200" style="color: #B4B4B4;">
					备注:
				</view>
				<view class="w480" style="word-break: break-word;color: red;">
					{{ info.remark || '' }}
				</view>
			</view>
		<!-- 	<view class="flex mb10">
				<view class="w200">
					生产单号:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.saleOrderCode || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					制单日期:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.createTime || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					交货日期:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.deliveryDate || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					配件名称:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.materialName || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					生产数量:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.lastCompleteNumber || '' }}
				</view>
			</view> -->

			<!-- <view class="flex mb10">
				<view class="w200">
					备注:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.remark || '' }}
				</view>
			</view> -->
		</view>


		<view class="footer">
			<view class="flex" style="padding: 0 50rpx;">
				<u-button v-if="info.workName" @click="handleAssemblyInformation" type="success" :text="'开始' + info.workName"></u-button>
				<view v-if="info.workName" class="ml20 mr20"></view>
				<u-button @click="handlComplete" type="primary" text="完结"></u-button>
			</view>

			<!-- 
			<view class="text">
				该订单还未进入到您所属的工序中，暂时无法进行操作
			</view> -->
		</view>

		<!-- 工序完结 -->
		<u-modal :show="processShow" @confirm="handleProcessConfirm" @cancel="processShow=false" showCancelButton
			title="提示" :content='submitContent'></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				ids: '',
				info: {},
				category: '',
				orderOperation: '',

				title: '',
				processShow: false,
				submitContent: '',
				expand: false,
			}
		},
		onLoad(e) {
			this.ids = e.id
			this.orderOperation = e.type
		},
		onShow() {
			this.handleInfo()
		},
		methods: {
			// 获取相信信息
			async handleInfo() {
				try {
					const {
						data
					} = await this.$api.getMicroCustomizedEditionApi(this.ids)

					this.info = data
					this.handleCategory()


					if (data.typeName == '餐具盒定制') {
						this.type = 1
						this.title = '餐具盒生产信息'
						uni.setNavigationBarTitle({
							title: `餐具盒生产单`
						});
					} else if (data.typeName == '不锈钢定制') {
						this.type = 2
						this.title = '不锈钢生产信息'
						uni.setNavigationBarTitle({
							title: `不锈钢生产单`
						});
					} else {
						this.type = 3
						this.title = '生日帽生产信息'
						uni.setNavigationBarTitle({
							title: `生日帽生产单`
						});
					}

				} catch (error) {
					//TODO handle the exception
					console.log(error, '报错')
				}
			},
			/** 跳转录入组装信息 */
			async handleAssemblyInformation() {

				if (!this.info.workProduceId) return this.$msg.error('该生产单已完成')

				const {
					data
				} = await this.$api.getCheckPermissions({
					orderOperation: this.orderOperation,
					processNumber: this.info.workProduceId,
					semiFlag: 0
				})

				if (data == 1) {
					if (this.info.lastCompleteStatus != 2) {
						this.ToPage(
							`/pagesIndex/microCustomizedEdition/enter?id=${this.info.id}&relationId=${this.info.relationId}&materialName=${this.info.materialName}&customerName=${this.info.customerName}(${this.info.personCount})&type=${this.type}&saleOrderCode=${this.info.saleOrderCode}&createTime=${this.info.createTime}-${this.info.deliveryDate}&applyNumber=${this.info.applyNumber}&remark=${this.info.remark}`
						)
					} else {
						this.$msg.error('该生产单已完成')
					}
				} else {
					this.$msg.error('您没有此权限')
				}
			},

			async handlComplete() {
				if (this.info.lastCompleteStatus != 2) return this.$msg.error('此订单还有其它工序未完结，无法完结订单')

				const {
					data
				} = await this.$api.getCheckPermissions({
					orderOperation: this.orderOperation,
					processNumber: 4,
					semiFlag: 0
				})

				if (data === '1') {
					this.submitContent = '上一道工序总共完成数量:' + this.info.lastCompleteNumber + '个,点击确认后自动全部入库，是否确认?'

					this.processShow = true
				} else {
					this.$msg.error('您没有此权限')
				}
			},

			async handleProcessConfirm() {
				try {
					await this.$api.putSpecialEditionStorage({
						id: this.info.customizedProductId,
						typeId: this.info.typeId,
						number: this.info.lastCompleteNumber,
						relationId: this.info.productId,
						customizedRelationId:  this.info.relationId
					})

					this.processShow = false
					this.$msg.success('操作成功!')

					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}, 1000)
				} catch (error) {
					//TODO handle the exception
				}
			},

			async handleCategory() {
				const _this = this
				try {
					const {
						data
					} = await this.$api.getDictionary('customized_order_type')

					data.forEach(item => {
						if (item.dictValue == _this.info.productType) {
							_this.category = item.dictLabel
						}
					})
				} catch (error) {
					//TODO handle the exception
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.assemblyOrder-container {
		width: 100%;
		min-height: 100vh;
		background-color: #F5F5F5;

		.dome {
			background-color: #FFFFFF;
			border-radius: 8rpx;
			margin: 10rpx auto;
			width: 710rpx;
		}


		.footer {
			// position: fixed;
			// bottom: 0;
			// left: 0;
			// width: 750rpx;
			padding-bottom: 150rpx;
			margin-top: 100rpx;

			.text {
				width: 100%;
				text-align: center;
				color: #F76C5F;
				font-size: 26rpx;
			}
		}
	}
</style>